import { Component, Input, OnInit } from '@angular/core';
import { Article } from '../article';

@Component({
  selector: 'app-article-list',
  templateUrl: './article-list.component.html',
  styleUrls: ['./article-list.component.css']
})
export class ArticleListComponent implements OnInit {
  @Input() articles: Article[];
  constructor() {
    this.articles = [ 
      new Article('Angular 2', 'http://angular.io', 3), 
      new Article('Fullstack', 'http://fullstack.io', 2), 
      new Article('Angular Homepage', 'http://angular.io', 1), 
      ]; 
   }

  ngOnInit(): void {
  }

  sortedArticles(): Article[] { 
    return this.articles.sort((a: Article, b: Article) => b.votes - a.votes); 
    } 
}
